package com.qf.hsr.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author q
 * @version V1.0
 * @date 2021/11/15
 **/
public class FirstInterceptor implements HandlerInterceptor {

    //在Handler执行之前执行【可以权限控制】
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("FirstInterceptor preHandle --->");
        //true 放行，false拦截
        return true;
    }

    //在Handler执行之后，渲染视图之前执行【可以改变视图】
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("FirstInterceptor postHandle --->");
    }

    //在渲染视图之后执行【释放资源】
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("FirstInterceptor afterCompletion --->");
    }
}
